package me.helllp.dake.generator.engine;

import freemarker.template.TemplateException;
import me.helllp.dake.generator.config.ProjectConfiguration;
import me.helllp.dake.generator.meta.ComponentProjectMetaData;
import me.helllp.dake.generator.meta.MicroServiceMetaData;
import me.helllp.dake.generator.meta.NormalServiceMetaData;
import me.helllp.dake.generator.meta.ProjectMetaData;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * 代码生成器的配置信息转换为MetaData信息
 */
public class MetaDataBuilder {
    /**
     * 根据项目配置信息获取项目元数据信息
     *
     * @param projectConfiguration 项目配置信息
     * @return
     */
    public static ProjectMetaData builder(ProjectConfiguration projectConfiguration) throws TemplateException, IOException, InvocationTargetException, IllegalAccessException {
        ProjectMetaData metaData = null;
        switch (projectConfiguration.getProjectType()){
            case COMPONENT:
                metaData = new ComponentProjectMetaData(projectConfiguration);
                break;
            case MICRO_SERVICE:
                metaData = new NormalServiceMetaData(projectConfiguration);
                break;
            case NORMAL_SERVICE:
                metaData = new MicroServiceMetaData(projectConfiguration);
                break;
        }

        if(metaData == null) {
            throw new RuntimeException("项目类型不支持");
        }

        return metaData;
    }

}
